﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using Jumbot.Common;
using Jumbot.DataOper;

namespace JumbotCms.DataObject
{
    /// <summary>
    /// 栏目表信息
    /// </summary>
    public class Class
    {
        private string m_Id = "0";
        private int m_ChannelId = 0;
        private string m_Title = string.Empty;
        private int m_ParentId;
        private string m_Info;
        private string m_Number;
        private string m_Code;
        private bool m_IsPost;
        private bool m_IsTop;
        private int m_TopicNum = 0;
        private int m_TemplateId;
        private int m_ContentTemp;
        private int m_PageSize;
        private bool m_IsOut;
        private string m_OutUrl;

        public string Id
        {
            get { return m_Id; }
            set { m_Id = value; }
        }
        public int ChannelId
        {
            set { m_ChannelId = value; }
            get { return m_ChannelId; }
        }
        public string Title
        {
            set { m_Title = value; }
            get { return m_Title; }
        }
        public int ParentId
        {
            set { m_ParentId = value; }
            get { return m_ParentId; }
        }
        public string Info
        {
            set { m_Info = value; }
            get { return m_Info; }
        }
        public string Number
        {
            set { m_Number = value; }
            get { return m_Number; }
        }
        public string Code
        {
            set { m_Code = value; }
            get { return m_Code; }
        }
        public bool IsPost
        {
            set { m_IsPost = value; }
            get { return m_IsPost; }
        }
        public bool IsTop
        {
            set { m_IsTop = value; }
            get { return m_IsTop; }
        }

        public int TopicNum
        {
            set { m_TopicNum = value; }
            get { return m_TopicNum; }
        }
		public int TemplateId
        {
            get { return m_TemplateId; }
            set { m_TemplateId = value; }
        }
        public int ContentTemp
        {
            set { m_ContentTemp = value; }
            get { return m_ContentTemp; }
        }
        public int PageSize
        {
            set { m_PageSize = value; }
            get { return m_PageSize; }
        }
        public bool IsOut
        {
            set { m_IsOut = value; }
            get { return m_IsOut; }
        }
        public string OutUrl
        {
            set { m_OutUrl = value; }
            get { return m_OutUrl; }
        }
        public Class()
        {
        }
        /// <summary>
        /// 获得所有数据
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="doh"></param>
        public void GetAllColumn(string _id, DbOperHandler doh)
        {

            doh.Reset();
            doh.SqlCmd = "SELECT * FROM [jcms_normal_class] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                Id = _id;
                ChannelId = Validator.StrToInt(dr["ChannelId"].ToString(), 0);
                Title = dr["Title"].ToString();
                ParentId = Validator.StrToInt(dr["ParentId"].ToString(), 0);
                Info = dr["Info"].ToString();
                Number = dr["Number"].ToString();
                Code = dr["Code"].ToString();
                IsPost = dr["IsPost"].ToString() == "1";
                IsTop = dr["IsTop"].ToString() == "1";
                TopicNum = Validator.StrToInt(dr["TopicNum"].ToString(), 0);
                TemplateId = Validator.StrToInt(dr["TemplateId"].ToString(), 0);
                ContentTemp = Validator.StrToInt(dr["ContentTemp"].ToString(), 0);
                PageSize = Validator.StrToInt(dr["PageSize"].ToString(), 20);
                IsOut = dr["IsOut"].ToString() == "1";
                OutUrl = dr["OutUrl"].ToString();
            }
        }
        /// <summary>
        /// 获得部分数据：Id,ChannelId,IsOut,OutUrl
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="doh"></param>
        public void GetPartColumn(string _id, DbOperHandler doh)
        {

            doh.Reset();
            doh.SqlCmd = "SELECT [Id],[ChannelId],[IsOut],[OutUrl] FROM [jcms_normal_class] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                Id = _id;
                ChannelId = Validator.StrToInt(dr["ChannelId"].ToString(), 0);
                IsOut = dr["IsOut"].ToString() == "1";
                OutUrl = dr["OutUrl"].ToString();
            }
        }
        public int GetIsOut(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [IsOut] FROM [jcms_normal_class] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["IsOut"].ToString(), 0);
            }
            return 0;
        }
        public string GetOutUrl(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [OutUrl] FROM [jcms_normal_class] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["OutUrl"].ToString();
            }
            return string.Empty;
        }
        /// <summary>
        /// 获得栏目名称
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="doh"></param>
        /// <returns></returns>
        public string GetClassName(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.ConditionExpress = "id=" + _id;
            return doh.GetValue("jcms_normal_class", "Title").ToString();
        }
        public bool HasChild(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.ConditionExpress = "parentid=" + _id;
            if (doh.Exist("jcms_normal_class"))
                return true;
            else
                return false;
        }
    }
}
